package com.iknow.util;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlSerializer;

public class DomXmlUtil
{
  public static final String CODING = "UTF-8";

  private static void dealNode(Node paramNode, XmlSerializer paramXmlSerializer)
    throws IllegalArgumentException, IllegalStateException, DOMException, IOException
  {
    NodeList localNodeList;
    int k;
    int l;
    if (paramNode.getNodeType() == 3)
    {
      paramXmlSerializer.text(paramNode.getNodeValue());
      return;
    }
    paramXmlSerializer.startTag("", paramNode.getNodeName());
    String str = paramNode.getNodeValue();
    if (str != null)
      paramXmlSerializer.text(str);
    NamedNodeMap localNamedNodeMap = paramNode.getAttributes();
    int i = localNamedNodeMap.getLength();
    int j = 0;
    if (j >= i)
    {
      localNodeList = paramNode.getChildNodes();
      k = localNodeList.getLength();
      l = 0;
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          if (l < k)
            break label170;
          paramXmlSerializer.endTag("", paramNode.getNodeName());
        }
        Node localNode = localNamedNodeMap.item(j);
        paramXmlSerializer.attribute("", localNode.getNodeName(), localNode.getNodeValue());
        ++j;
      }
      label170: dealNode(localNodeList.item(l), paramXmlSerializer);
      ++l;
    }
  }

  public static String getAttributes(Node paramNode, String paramString)
  {
    String str = null;
    if (paramNode == null);
    while (true)
    {
      Node localNode;
      do
      {
        NamedNodeMap localNamedNodeMap;
        do
        {
          return str;
          localNamedNodeMap = paramNode.getAttributes();
        }
        while (localNamedNodeMap == null);
        localNode = localNamedNodeMap.getNamedItem(paramString);
      }
      while (localNode == null);
      str = localNode.getNodeValue();
    }
  }

  public static String getCurrentText(Node paramNode)
  {
    String str2;
    if (paramNode == null)
      str2 = null;
    while (true)
    {
      return str2;
      if (paramNode.getNodeType() != 3)
        break;
      str2 = paramNode.getNodeValue();
    }
    NodeList localNodeList = paramNode.getChildNodes();
    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0;
    while (true)
    {
      while (i >= localNodeList.getLength())
        str2 = localStringBuffer.toString();
      Node localNode = localNodeList.item(i);
      if (localNode.getNodeType() == 3)
      {
        String str1 = localNode.getNodeValue();
        if ((!(StringUtil.isEmpty(str1))) && (!(StringUtil.equalsString(localStringBuffer, "null"))))
          localStringBuffer.append(str1);
      }
      ++i;
    }
  }

  public static String getTagItemValue(Node paramNode, String paramString)
  {
    String str;
    if (paramNode == null)
    {
      str = null;
      return str;
    }
    NodeList localNodeList = paramNode.getChildNodes();
    int i = 0;
    while (true)
    {
      while (true)
      {
        while (i >= localNodeList.getLength())
          str = "";
        Node localNode = localNodeList.item(i);
        if (!(StringUtil.equalsString(paramString, localNode.getNodeName())))
          break;
        str = getCurrentText(localNode);
      }
      ++i;
    }
  }

  public static Node paseXml(String paramString)
  {
    Object localObject = null;
    DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
    try
    {
      ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramString.getBytes());
      Node localNode = localDocumentBuilderFactory.newDocumentBuilder().parse(localByteArrayInputStream).getFirstChild();
      localObject = localNode;
      return localObject;
    }
    catch (ParserConfigurationException localParserConfigurationException)
    {
      localParserConfigurationException.printStackTrace();
    }
    catch (SAXException localSAXException)
    {
      localSAXException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }

  // ERROR //
  public static void print(java.io.OutputStream paramOutputStream, org.w3c.dom.Element paramElement)
  {
    // Byte code:
    //   0: invokestatic 163	android/util/Xml:newSerializer	()Lorg/xmlpull/v1/XmlSerializer;
    //   3: astore_2
    //   4: aload_2
    //   5: aload_0
    //   6: ldc 8
    //   8: invokeinterface 167 3 0
    //   13: aload_1
    //   14: aload_2
    //   15: invokestatic 78	com/iknow/util/DomXmlUtil:dealNode	(Lorg/w3c/dom/Node;Lorg/xmlpull/v1/XmlSerializer;)V
    //   18: aload_2
    //   19: invokeinterface 170 1 0
    //   24: aload_0
    //   25: ifnull +7 -> 32
    //   28: aload_0
    //   29: invokevirtual 175	java/io/OutputStream:close	()V
    //   32: return
    //   33: astore 5
    //   35: new 177	java/lang/RuntimeException
    //   38: dup
    //   39: aload 5
    //   41: invokespecial 180	java/lang/RuntimeException:<init>	(Ljava/lang/Throwable;)V
    //   44: athrow
    //   45: astore_3
    //   46: aload_0
    //   47: ifnull +7 -> 54
    //   50: aload_0
    //   51: invokevirtual 175	java/io/OutputStream:close	()V
    //   54: aload_3
    //   55: athrow
    //   56: astore 4
    //   58: new 177	java/lang/RuntimeException
    //   61: dup
    //   62: aload 4
    //   64: invokespecial 180	java/lang/RuntimeException:<init>	(Ljava/lang/Throwable;)V
    //   67: athrow
    //   68: astore 6
    //   70: new 177	java/lang/RuntimeException
    //   73: dup
    //   74: aload 6
    //   76: invokespecial 180	java/lang/RuntimeException:<init>	(Ljava/lang/Throwable;)V
    //   79: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   4	24	33	java/lang/Exception
    //   4	24	45	finally
    //   35	45	45	finally
    //   50	54	56	IOException
    //   28	32	68	IOException
  }
}